#pragma once
#include "..\Common\Global.h"

template <typename I,typename O>
class Combinator_Any : public Combinator<I,O>
{
public:
	Combinator_Any(Combinator_Node<I,O>& _left,int _count,Combinator_MemoryManager<I,O>* _MM) : left(_left),count(_count),Combinator(_MM){}

	virtual O Parser(I& input)
	{
		if(count > 0)
		{
			O Result(GetMM());
			O Result1(GetMM());
			for(int i=0;i<count;i++)
			{
				I temp = input;
				if(!(Result1 = left.Parser(input)))
				{
					return Result;
				}
				if(input == temp) break;
				Result = Result + Result1;
			}
			return Result;
		}
		else
		{
			O Result(GetMM());
			O Result1(GetMM());
			while(TRUE)
			{
				I temp = input;
				if(!(Result1 = left.Parser(input)))
				{
					Result.SetResult(TRUE);
					return Result;
				}
				if(input == temp)
				{
					//Result.SetResult(TRUE);
					break;
				}
				Result = Result + Result1;
			}
			return Result;
		}
	}
protected:
	Combinator_Node<I,O>& left;
	int count;
};